<input type="hidden" id="new_event_status" value="<?php echo $this->session->flashdata('new_event_status'); ?>" />
<script type="text/javascript">
  $(document).ready(function() {
    $("#event_date").datepicker({
      format: 'dd-mm-yyyy',
      startDate: new Date()
    });
    var new_event_status = $.trim($('#new_event_status').val());
    if (new_event_status == 2) {
      toastr.error('Invalid date');
      return false;
    }
    if (new_event_status == 3) {
      toastr.error('Error occured. Try again !');
      return false;
    }
  });
</script>

<div class="page" style="min-height: 500px;">
  <div class="page-container">
    <div class="container">
      <div class="row">
        <div class="span12 header">
          <div class="btn-group pull-right">
            <a href="<?php echo base_url('event/myevents'); ?>" class="btn pull-right">My Events</a>
          </div>
          <h4>New event</h4>
        </div>
        <div class="span6">
          <form method="post" action="<?php echo base_url('event/create'); ?>" class="form-horizontal" onsubmit="return confirm_action('Save & publish event ?');">
            <input type="hidden" name="csrf_token" value="<?php echo set_csrf_token(); ?>"/>
            <div class="control-group">
              <label class="control-label">Event Date </label>
              <div class="controls">
                <input name="event_date" id="event_date" type="text" placeholder="Date" value="<?php echo $event_date; ?>"/>&nbsp;<i class="icon-calendar"></i>
              </div>
            </div>
            <div class="control-group">
              <label class="control-label">Event message </label>
              <div class="controls">
                <input name="event_message" id="event_message" type="text" style="width: 150%;" placeholder="Event message (250)" value="<?php echo $event_message; ?>" maxlength="250"/>
              </div>
            </div>
            <div class="control-group"> 
              <div class="controls">
                <button type="submit" class="btn" onclick="return validate_event();">Create</button>
              </div>
            </div>
          </form>
        </div>
      </div>
      <div class="row">
        <div class="span12 header">
          <h4>My events</h4>
        </div>
        <table class="table" style="margin-left: 50px; width: 93%;">
          <tbody>
            <?php if (!empty($my_events)) { ?>
              <tr>
                <td width="20%"><b>Date</b></td>
                <td width="60%"><b>Message</b></td>
                <td width="20%"><b>Action</b></td>
              </tr>
              <?php foreach ($my_events as $my_event) { ?>
                <tr>
                  <td><?php echo date('d - F - Y', strtotime($my_event['event_date'])); ?></td>
                  <td style="word-break: break-all;"><?php echo substr($my_event['event_message'], 0, 75) . '...'; ?></td>
                  <td>
                    <a style="text-decoration: none;" href="<?php echo base_url('event/update/' . $my_event['event_id']); ?>">Update</a>
                    |
                    <a onclick="return confirm_action('Are you sure to delete this event ?')" style="text-decoration: none;" href="<?php echo base_url('event/delete/' . $my_event['event_id']); ?>">Delete</a>
                  </td>
                </tr>
              <?php } ?>
            <?php } else { ?>
            <div style="margin-left: 50px;">
              No events !
            </div>
          <?php } ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>